// 头像

cc.Class({
    extends: cc.Component,

    properties: {
        m_iconNode : cc.Node,                   // 桌子上所有玩家头像的父节点
        m_playerIocn : [],               
    },

    onLoad () {
        this.m_playerIocn = [];
    },

    start () {
        // 取出4个玩家的头像信息
        for (var i = 0; i < this.m_iconNode.children.length; i++) {
            var node = this.m_iconNode.children[i];
            this.m_playerIocn.push(node);
        }

        for(var num = 0; num < 4; ++num)
        {
            this.SetScore(num, 50);
            this.SetName(num, ("帝释天" + num));
            this.SetIcon(num);
        }
    },

    // 设置头像
    SetIcon : function(playerID) {
        var sprite = this.m_playerIocn[playerID].getChildByName("IconBgBox").getChildByName("New Node").getChildByName("iconImg").getComponent(cc.Sprite);
        var realUrl = cc.url.raw('resources/Communal/4.png');
        cc.loader.load(realUrl, function (err, texture) {
            var w = sprite.node.width;
            var h = sprite.node.height;
            var frame = new cc.SpriteFrame(texture);
            sprite.spriteFrame = frame;
            // sprite.node.width = w;
            // sprite.node.height = h;
            // var xy1 = sprite.node.x;
            // var xy2 = sprite.node.y;
            // sprite.node.x = xy1;
            // sprite.node.y = xy2;
        });
    },

    // 分数设置
    // playerID                     玩家ID
    // scoer                        分数
    SetScore : function(playerID, scoer) {
        var aa = this.m_playerIocn[playerID].getChildByName("FenShu");
        var aa1 = aa.getChildByName("scoer");
        this.m_playerIocn[playerID].getChildByName("FenShu").getChildByName("scoer").getComponent(cc.Label).string = scoer;
    },

    // 名字设置
    // playerID                     玩家ID
    // name                         名字
    SetName : function(playerID, name){
        this.m_playerIocn[playerID].getChildByName("NameBgBox").getChildByName("Name").getComponent(cc.Label).string = name;
    },
});
